<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}

$params = array();
array_push($params, pg_escape_string($_GET["id"]));
$stmt = pg_prepare($connect, "read_purcharse_header", "SELECT 
  purcharse_header.emission_date, 
  purcharse_header.total, 
  purcharse_header.serie, 
  purcharse_header.number, 
  purcharse_header.cancellation_date, 
  purcharse_header.igv, 
  purcharse_header.subtotal, 
  purcharse_supplier.name, 
  purcharse_supplier.ruc, 
  purcharse_supplier.address
FROM 
  public.purcharse_header, 
  public.purcharse_supplier
WHERE 
  purcharse_header.supplier_id = purcharse_supplier.id AND purcharse_header.id = $1;");
$result = pg_execute($connect, "read_purcharse_header", $params);

if (!$result) {
    die("Error in SQL query: " . pg_last_error());
}
$arrRegistros = pg_fetch_all($result);
echo json_encode($arrRegistros);
pg_free_result($result);
pg_close($connect);


